<?php
/**
 * comment.class.php
 */

class comment
{
	var $db;
	var $mutipage;
	
	function __construct()
	{
		global $db, $tablepre;
		$this->db = &$db;
		$this->tablepre = $tablepre;
		$this->table_content = $this->tablepre.'comment';
		$this->table = '';
	}
	
	function comment()
	{
		$this->__construct();
	}
	
	function show($dataid, $type, $pageurl, $page = 1, $perpage = 10)
	 {
		$page = max(intval($page), 1);
		$offset = $perpage*($page-1);
		$limit = " LIMIT $offset, $perpage";
		$sql = $where = '';
		$where = $dataid ? " WHERE `contentid`='$dataid' AND `status`='1'" : '';
		$sql = "SELECT * FROM `$this->table_content` $where";
		$total = $this->db->num_rows($this->db->query($sql));
		$this->mutipage = multi($total, $perpage, $page, $pageurl);
		$sql.=" ORDER BY `commentid` DESC $limit";
		$data = $this->db->fetch_all($sql);
		return $data;
	}
	
	function del($commentid, $table='content')
	{
		$this->table = $this->table_content;
		
		if(is_array($commentid))
		{
			$aff=0;
			foreach ($commentid as $key=>$val)
			{
				$query = $this->db->query("DELETE FROM `$this->table` WHERE `commentid`='$val'");
				$aff += $this->db->affected_rows();
			}
		}
		else
		{
			$query = $this->db->query("DELETE FROM `$this->table` WHERE `commentid`='$commentid'");
		}
		unset($this->table);
		if($query) return $aff;
	}
	
	function verify($commentid, $table='shop')
	{
		$this->table = $this->table_content;
		if(is_array($commentid))
		{
			$aff = 0;
			foreach ($commentid as $key=>$val)
			{
				$query = $this->db->query("UPDATE `$this->table` SET `status`='1' WHERE `commentid`='$val'");
				$aff += $this->db->affected_rows();
			}
		}
		else
		{
			$query = $this->db->query("UPDATE `$this->table` SET `status`='1' WHERE `commentid`='$commentid'");
		}
		unset($this->table);
		if($query) 	return $aff;
	}
}
?>